.global main, move
.section .data
.section .rodata
.LC0:
	.string "%c -> %c\n"
.text

move:
	pushl %ebp
	movl %esp, %ebp

	pushl %ebx
	subl $20, %esp

	// from
	movl 12(%ebp), %eax
	movb %al, -12(%ebp)

	// trans
	movl 16(%ebp), %eax
	movb %al, -16(%ebp)

	// to
	movl 20(%ebp), %eax
	movb %al, -20(%ebp)

	cmpl $1, 8(%ebp)
	je .LCmove_10

	// move(n - 1, from, to, trans)
	// trans
	movsbl -16(%ebp), %eax
	pushl %eax
	// to
	movsbl -20(%ebp), %eax
	pushl %eax
	// from
	movsbl -12(%ebp), %eax
	pushl %eax
	movl 8(%ebp), %eax
	subl $1, %eax
	pushl %eax
	call move
	addl $16, %esp

	subl $4, %esp
	movsbl -20(%ebp), %eax
	pushl %eax
	movsbl -12(%ebp), %eax
	pushl %eax
	pushl $.LC0
	call printf
	addl $16, %esp

	movsbl -20(%ebp), %eax
	pushl %eax
	movsbl -12(%ebp), %eax
	pushl %eax
	movsbl -16(%ebp), %eax
	pushl %eax
	movl 8(%ebp), %eax
	subl $1, %eax
	pushl %eax
	call move
	addl $16, %esp
	jmp .LCmove_17

.LCmove_10:
	subl $4, %esp
	// to
	movsbl -20(%ebp), %eax
	pushl %eax
	// from
	movsbl -12(%ebp), %eax
	pushl %eax
	pushl $.LC0
	call printf
	addl $16, %esp

.LCmove_17:
	movl $0, %eax
	movl -4(%ebp), %ebx
	leave
	ret

main:
	pushl %ebp
	movl %esp, %ebp

	subl $8, %esp
	pushl $'C'
	pushl $'B'
	pushl $'A'
	pushl $3
	call move
	addl $24, %esp

	movl $0, %eax
	leave
	ret
